package com.keiou.drink.util;

import android.content.Context;
import android.widget.Toast;

/**
 * Created by Bob on 2016/4/25
 */
public class CToast {


    private static String lastToast = "";
    private static long lastToastTime;


    public static void showLong(Context context, String message) {
        showToast(context, message, Toast.LENGTH_LONG);
    }


    public static void showShort(Context context, String message) {
        showToast(context, message, Toast.LENGTH_SHORT);
    }


    /**
     * 防止重复弹出
     *
     * @param context
     * @param message
     * @param duration
     */
    public static void showToast(Context context, String message, int duration) {
        if (message != null && !message.equalsIgnoreCase("")) {
            long time = System.currentTimeMillis();
            if (!message.equalsIgnoreCase(lastToast)
                    || Math.abs(time - lastToastTime) > 1000) {
                Toast.makeText(context, message, duration).show();
                lastToast = message;
                lastToastTime = System.currentTimeMillis();
            }
        }
    }

}
